#ifndef __AKY_TASK_0_H__
#define __AKY_TASK_0_H__
#include "aky_program/aky_func.h"
#include "aky_program/aky_define.h"


typedef enum
{
    TASK_0_STAT_FREE = 0,
    TASK_0_STAT_ZERO,
    TASK_0_STAT_ZERO_END,
    TASK_0_STAT_CAL_MODE,
    TASK_0_STAT_ERR,
    TASK_0_STAT_CAL_SUCC,
    TASK_0_STAT_CAL_ERR,
    TASK_0_STAT_TESTING,
    TASK_0_STAT_TEST_SUCC,
    TASK_0_STAT_TEST_FAIL,
    TASK_0_STAT_PER_READY,
    TASK_0_STAT_PER_WAIT,
    TASK_0_STAT_PER_ING,
    TASK_0_STAT_PER_FAIL,
    TASK_0_STAT_PER_OVER,
    TASK_0_STAT_MEM_GAIN,
    TASK_0_STAT_MEM_GAIN_OVER,
    TASK_0_STAT_MEM_DELEAT,
    TASK_0_STAT_MEM_DELEAT_OVER,
    TASK_0_STAT_SHOWRESULT,
    TASK_0_STAT_C,
    TASK_0_STAT_CAL,
    TASK_0_STAT_LIFETEST,
    TASK_0_STAT_FAST_TEST,
    TASK_0_STAT_WRITE_MEM,
    TASK_0_STAT_DOWN_CHANGE,//关机充电
    TASK_0_STAT_STOPMODE,   //关机

} e_aky_task_0_stat_t;

typedef struct
{
    e_aky_task_0_stat_t e_aky_task_0_stat; // 状态
    uint8_t transfer_year;                 //开机同步时间
    uint8_t transfer_month;
    uint8_t transfer_day; 
    uint8_t transfer_hour; 
    uint8_t transfer_min; 
    uint8_t transfer_secon;
    uint8_t transfer_voice;                //传递是否有语音
    uint8_t transfer_uint;                 //传递单位

    uint8_t version_mon;                    //版本月
    uint8_t version_date;                   //版本日

    uint16_t pres_mmg;                     // 压力值
    uint16_t pres_sys;                     // 高压值
    uint16_t pres_dia;                     // 低压值
    uint8_t result;                        // 测试结果判断
    uint8_t pulse;                         // 心率
    uint8_t PAD;                           // 心率不齐
    uint8_t PER_Mode;                      // 预适应模式
    uint8_t pre_hold_time;                      // 预适应阶段保压时间
    uint16_t pre_set;                      // 预适应压力设定
    uint16_t pre_keep_pres;                      // 预适应阶段保压压力

    uint8_t flag_reply;                      // 回复 0x88

    uint16_t PER_Alltime;                  // 预适应总时间
    uint16_t PER_Steptime;                 // 预适应第一阶段时间
    uint8_t PER_PumpStatus;                // 预适应泵的状态
    uint8_t ERRORCode;                     // 错误码

    uint8_t MEM_INDEX;                     // 记忆索引号
    uint16_t MEM_pres_sys;                 // 记忆高压值
    uint16_t MEM_pres_dia;                 // 记忆低压值
    uint8_t MEM_pulse;                     // 记忆心率
    uint8_t MEM_PAD;                       // 记忆心率不齐
    uint8_t Mem_year;                  
    uint8_t Mem_month;                 
    uint8_t Mem_day;                   
    uint8_t Mem_hour;                  
    uint8_t Mem_min;    
    uint8_t Mem_secon;  
    uint8_t WriteMem_time;                 //写记忆组数
    uint8_t WriteMem_ok;                   //写记忆完成
    uint8_t flag_time_get_succ;                   //
    s_time_t s_get_time;

    uint16_t adc_count;                    // 传感器adc值
    uint16_t CAL_pres_meansuring;
    uint16_t Lefttestnumber;
    uint8_t cal_succ_code; // 校压成功码  1 成功  2 失败
    uint8_t step_code; // 训练第N阶段结束，N < 9，仅主机血压计发送该指令
    uint8_t flag_step_end; // 
    uint8_t step_code_last; // 
    uint8_t flag_get_engi_pres_cmd; // 

} stru_aky_task_0_t;

typedef enum
{
    TASK0_BP_READY_Command = 0xA1,      // 准备血压测量
    TASK0_BP_START_Command,             // 开始血压测量
    TASK0_PER_PREPARE_Command,          //预适应准备 a3
    TASK0_PER_START_Command,            //预适应开始加压
    TASK0_PER_UP = 0xa6,            //预适应压力加
    TASK0_PER_DOWN = 0xa7,            //预适应压力减
    TASK0_TIME_ADJUST = 0xa8,            //预适应压时间调节

    TASK0_MEM_GAIN_Command = 0xB1,      //获取记忆
    TASK0_MEM_DELEAT_Command = 0xB3,    //删除记忆

    TASK0_EMC_Command = 0xAA,
    
    TASK0_BP_STOP_Command = 0xAF,   // 停止测量
    TASK0_BP_DOWN_Command = 0xF1,   // 关机
    TASK0_CAL_Command = 0xF2,
    TASK0_LifeTest_Command = 0xF3,
    TASK0_MEM_WRITE_Command = 0xF4,   // 写记忆
    TASK0_C_Command = 0xF5,
    TASK0_4G_TIME_Command = 0xF6,         // 更4G时间
    TASK0_get_TIME_Command = 0xF7,         // 获取本地时间
    TASK0_ENTER_EMC = 0xF8,  // EMC

    TASK0_BP_CALOK_Command = 0xF9,  // 校压确认键
    TASK0_BP_ENGINE_EXIT = 0xF9,  // 退出工程模式

    TASK0_CHARGE_POWER_ON = 0xFA,  // 充电手动开机
    TASK0_FAST_TEST_MODE = 0xFB,  // 快速测试模式


} e_aky_Mcu_task0contrl;

extern stru_aky_task_0_t Task0_BP;
extern uint8_t flag_aky_uart_0_judge;
#define aky_task_0_get_data() Task0_BP


void aky_task_0(void); // 任务入口
void aky_task_0_init(void);
void aky_task_0_send_cmd(e_aky_Mcu_task0contrl cmd);
// stru_aky_task_0_t aky_task_0_get_data(void);
uint8_t Cal_CRC0(uint8_t len);
void Send_BLe_data0(uint8_t secdlen);
void send_time_syn(s_time_t s_time);
void clr_get_time_flag(void);
void clr_task_0_data(void);


#endif